package cn.slahser.model;

import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Set;

import cn.slahser.server.ActionServer;

/***
 * 通知有新内容诞生
 * 
 * @author Slahser
 * 
 */
public class Action extends Thread {
	Message m = null;

	public Action(Message m) {
		this.m = m;
	}

	public void run() {
		// 由于登陆人数并发问题，clone一下
		@SuppressWarnings("unchecked")
		HashMap<String, ObjectOutputStream> map = (HashMap<String, ObjectOutputStream>) ActionServer.UserPool
				.clone();
		Set<String> keys = map.keySet();
		for (String string : keys) {
			try {
				// 拿出来value的是oops对象
				ObjectOutputStream out = map.get(string);
				//这个同步来处理同时发说说的问题
				synchronized (out) {
					out.writeObject(m);
					out.flush();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

}
